package com.ruoyi.web.controller.school;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.school.domain.PacCarouselBanner;
import com.ruoyi.school.service.PacCarouselBannerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api("轮播图相关接口")
@RestController
@RequestMapping("/school/carouselBanner")
public class PacCarouselBannerController extends BaseController {
    @Resource
    private PacCarouselBannerService pacCarouselBannerService;

    @ApiOperation("轮播列表")
    @GetMapping("/list")
    public TableDataInfo list(PacCarouselBanner pacCarouselBanner) {
        startPage();
        List<PacCarouselBanner> list = pacCarouselBannerService.getList(pacCarouselBanner);
        return getDataTable(list);
    }

    @ApiOperation("轮播详情")
    @GetMapping("/details")
    public AjaxResult details(PacCarouselBanner pacCarouselBanner) {
        PacCarouselBanner details = pacCarouselBannerService.getDetails(pacCarouselBanner);
        return success(details);
    }

    @ApiOperation("新增轮播图")
    @Log(title = "轮播图", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody PacCarouselBanner pacCarouselBanner) {
        boolean add = pacCarouselBannerService.add(pacCarouselBanner);
        return success(add);
    }

    @ApiOperation("更新轮播图")
    @Log(title = "轮播图", businessType = BusinessType.UPDATE)
    @PutMapping("/update")
    public AjaxResult update(@RequestBody PacCarouselBanner pacCarouselBanner) {
        boolean update = pacCarouselBannerService.edit(pacCarouselBanner);
        return success(update);
    }

    @ApiOperation("删除轮播图")
    @Log(title = "轮播图", businessType = BusinessType.DELETE)
    @DeleteMapping("/delete")
    public AjaxResult delete(PacCarouselBanner pacCarouselBanner) {
        boolean delete = pacCarouselBannerService.delete(pacCarouselBanner);
        return success(delete);
    }

    @Anonymous
    @GetMapping("/all")
    public AjaxResult all(PacCarouselBanner pacCarouselBanner) {
        List<PacCarouselBanner> list = pacCarouselBannerService.getAllList(pacCarouselBanner);
        return success(list);
    }
}
